 <?php
 session_start();
 include_once ("Login/databaseconnection.php");
 $current_table="deleted_school";
 date_default_timezone_set("Europe/Paris");
  	$t_d=date("Y/m/d");
   $Census_Number=$_GET['Census_Number'];
   $sqlre=mysql_query("SELECT * FROM deleted_school WHERE Census_Number='$Census_Number'");
	if(mysql_num_rows($sqlre)!=0)
	{
	$Principal_Name=$_POST['Principal_Name'];
	$School_Id=$_POST['School_Id'];
	$Zone=$_POST['Zone'];
	$Division=$_POST['Division'];
	$Province=$_POST['Province'];
	$District=$_POST['District'];
	$Census_Number=$_POST['Census_Number'];
	$Name=$_POST['Name'];
	$Status=$_POST['Status'];
	$Type=$_POST['Type'];
	$Grade_Range=$_POST['Grade_Range'];
	$Medium=$_POST['Medium'];
	$Female_Students=$_POST['Female_Students'];
	$Male_Students=$_POST['Male_Students'];
	$Tp_Number=$_POST['Tp_Number'];
	$Fax_Number=$_POST['Fax_Number'];
	$E_Mail=$_POST['E_Mail'];
	$Web_Address=$_POST['Web_Address'];
	$Address=$_POST['Address'];
	$Account_Number=$_POST['Account_Number'];
	$Special_Projects=$_POST['Special_Projects'];
    $Last_Updated_Date=$_POST['Last_Updated_Date'];
	$Accessed_By=$_POST['Accessed_By'];
	
		$sql=mysql_query("INSERT INTO school(Principal_Name,School_Id,Zone,Division,Province,District,Census_Number,Name,Status,Type,Grade_Range,Medium,Female_Students,Male_Students,Tp_Number,Fax_Number,E_Mail,Web_Address,Special_Projects,Address,Account_Number,Last_Updated_Date)VALUES('$Principal_Name','$School_Id','$Zone','$Division','$Province','$District','$Census_Number','$Name','$Status','$Type','$Grade_Range','$Medium','$Female_Students','$Male_Students','$Tp_Number','$Fax_Number','$E_Mail','$Web_Address','$S_Pro','$Address','$Account_Number','$t_d')");
if($sql)
{ 
if($row=mysql_fetch_array($sqlre))
	{
	$Comp_Id=$row['Competition_Id'];
	$No_Of_Stu=$row['No_Of_Students'];
	$No_Of_Tea=$row['No_Of_Teachers'];
	$Res=$row['Result'];
	$Dat=$row['Date'];
	$Sco=$row['Scope'];
   $Winn=$row['Winner'];
    $Required_Tea=$row['Required_Teachers'];
	$P_Id=$row['Pro_Id'];
	$Yea=$row['Year'];
	$No_S=$row['No_Stu'];
	$No_Tra_te=$row['No_Tera_tea'];
	$Tra_te=$row['Tra_tea'];
	$Avai_Bo=$row['Avai_Book'];
   $Avai_Tea_Gu=$row['Avai_Tea_Gui'];
   $Exam_Nam=$row['Exam_Name'];
   $Ye=$row['Year_Exa'];
   $No_Of_Sat_Stud=$row['No_Of_Sat_Students'];
   $No_Of_Passed_Stud=$row['No_Of_Passed_Students'];

   $Competition_Id=explode(",",$Comp_Id);
	$No_Of_Students=explode(",",$No_Of_Stu);
	$No_Of_Teachers=explode(",",$No_Of_Tea);
	$Result=explode(",",$Res);
	$Date=explode(",",$Dat);
	$Scope=explode(",",$Sco);
   $Winner=explode(",",$Winn);
    $Required_Teachers=explode(",",$Required_Tea);
	$Pro_Id=explode(",",$P_Id);
	$Year=explode(",",$Yea);
	$No_Stu=explode(",",$No_S);
	$No_Tra_tea=explode(",",$No_Tra_te);
	$Tra_tea=explode(",",$Tra_te);
	$Avai_Book=explode(",",$Avai_Bo);
   $Avai_Tea_Gui=explode(",",$Avai_Tea_Gu);
   $Exam_Name=explode(",",$Exam_Nam);
   $Exa_Year=explode(",",$Ye);
   $No_Of_Sat_Students=explode(",",$No_Of_Sat_Stud);
   $No_Of_Passed_Students=explode(",",$No_Of_Passed_Stud);
		$_SESSION['Accessed_By']=$Accessed_By;
		for($i=0;$i<count();$i++)
		{
		mysql_query("INSERT INTO programmes(Required_Teachers,Programme_Id,Year,School_Id,No_Of_Students,Teachers_In_Training,Trained_Teachers,Availability_Books,Availability_Tguides,Last_Updated_Date)values('$Required_Teachers[$i]','$Pro_Id[$i]','$Year[$i]','$Sch_Id[$i]','$No_Stu[$i]','$No_Tra_tea[$i]','$Tra_tea[$i]','$Avai_Book[$i]','$Avai_Tea_Gui[$i]','$t_d')");
	   }
		for($j=0;$j<count();$j++)
		{
		mysql_query("INSERT INTO competition(Competition_Id,School_Id,No_Of_Students,No_Of_Teachers,Result,Date,Scope,Winner,Last_Updated_Date)values('$Competition_Id[$j]','$School_Id[$j]','$No_Of_Students[$j]','$No_Of_Teachers[$j]','$Result[$j]','$Date[$j]','$Scope[$j]','$Winner[$j]','$t_d')");
        }
		for($k=0;$k<count();$k++)
		{
		mysql_query("INSERT INTO exam(School_Id,Exam_Name,Year,No_Of_Sat_Students,No_Of_Passed_Students,Last_Updated_Date) VALUES('$School_Id[$k]','$Exam_Name[$k]','$Exa_Year[$k]','$No_Of_Sat_Students[$k]','$No_Of_Passed_Students[$k]','$t_d')");
	    }
		}
	$resultdel=mysql_query("DELETE FROM deleted_school WHERE Census_Number='$Census_Number'");
if(!$resultdel)
{
	$sql=mysql_query("INSERT INTO school(Principal_Name,School_Id,Zone,Division,Province,District,Census_Number,Name,Status,Type,Grade_Range,Medium,Female_Students,Male_Students,Tp_Number,Fax_Number,E_Mail,Web_Address,Special_Projects,Address,Account_Number,Last_Updated_Date)VALUES('$Principal_Name','$School_Id','$Zone','$Division','$Province','$District','$Census_Number','$Name','$Status','$Type','$Grade_Range','$Medium','$Female_Students','$Male_Students','$Tp_Number','$Fax_Number','$E_Mail','$Web_Address','$S_Pro','$Address','$Account_Number','$t_d')");
	 $_SESSION['error']="but this record is not removed from the recycle bin!";
}
$_SESSION['error']="Successfully restored!";
}
   if(!$sql)
{
	 $_SESSION['error']="Sorry,an error occured  please try again!";
}	
}
?>
